package org.example.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Tag(name = "产品管理", description = "产品相关接口")
@RestController
@RequestMapping("/products")
public class ProductController {
    @Operation(summary = "获取产品列表", description = "可根据关键字过滤产品")
    @ApiResponse(responseCode = "200", description = "返回产品列表")
    @GetMapping
    public List<String> listProducts(
            @Parameter(description = "产品关键字", example = "苹")
            @RequestParam(value = "keyword", required = false) String keyword) {
        List<String> products = Arrays.asList("苹果", "香蕉", "橙子");
        if (keyword != null && !keyword.isEmpty()) {
            return products.stream().filter(p -> p.contains(keyword)).collect(Collectors.toList());
        }
        return products;
    }
} 